	//
//  WSFirstPopupViewController.m
//  CharonTVProject
//
//  Created by xunruiIOS on 2023/11/24.
//

#import "WSFirstPopupViewController.h"
#import "AppDelegate.h"
@interface WSFirstPopupViewController ()
@property (weak, nonatomic) IBOutlet UILabel *contentLab;
@property (weak, nonatomic) IBOutlet UIView *mainView;
@property (weak, nonatomic) IBOutlet UIButton *selectButton;

@end

@implementation WSFirstPopupViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self layoutBottomLabel];
    [self layoutBottomLabel2];
    // Do any additional setup after loading the view.
}

- (void)layoutBottomLabel {
    self.selectButton.selected = YES;
    self.contentLab.hidden = YES;
    YYLabel *label = [[YYLabel alloc] init];
    label.numberOfLines = 0;
    [self.mainView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(104);
        make.height.mas_equalTo(150);
    }];
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.alignment = NSTextAlignmentCenter;
    style.lineBreakMode = NSLineBreakByWordWrapping;
    NSString *text = APPLocalized(@"欢迎使用“咯戎微短剧”！我们非常重视您的个人信息和隐私保护。在开始使用我们的产品和服务前，请仔细阅读并了解《隐私政策》的全部内容，并同意全部条款。我们承诺按照您同意的条款使用您的个人信息，尽全力保护您的个人信息安全，以便为您提供安全、便捷、优质的服务。");
    NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:text
                                                                                 attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15], NSParagraphStyleAttributeName: style, NSForegroundColorAttributeName: UIColor.font_black_333333}];
    
    NSString *string2 = APPLocalized(@"《隱私政策》");
    [UIColor colorFromHexRGB:@""];
    NSRange range2 = [text rangeOfString:string2];
    [attrText addAttributes:@{NSUnderlineStyleAttributeName: @(1)} range:range2];
    [attrText setTextHighlightRange:range2 color:[UIColor colorFromHexRGB:@"2BACF4"] backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        UIViewController * target = [[CTMediator sharedInstance]ct_showWebWithUrl:API_CHARONTV_AGREEMENT_PRIVACY titleStr:@"隱私政策" showNav:YES closeHandle:^{}];
        [self.navigationController pushViewController:target animated:YES];
    }];
    

    label.attributedText = attrText;
    label.textAlignment = NSTextAlignmentLeft;
}

- (void)layoutBottomLabel2 {
    YYLabel *label = [[YYLabel alloc] init];
    [self.view addSubview:label];
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.alignment = NSTextAlignmentCenter;
    style.lineBreakMode = NSLineBreakByWordWrapping;
    NSString *text = @"注册即代表您已阅读并同意《用户协议》与《隐私政策》";
    NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:text
                                                                                 attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSParagraphStyleAttributeName: style, NSForegroundColorAttributeName: [UIColor colorFromHexRGB:@"C9C9C9"]}];
    
    NSString *string1 = @"《用户协议》";
    NSRange range1 = [text rangeOfString:string1];
    [attrText addAttributes:@{NSUnderlineStyleAttributeName: @(1)} range:range1];
    [attrText setTextHighlightRange:range1 color:[UIColor colorFromHexRGB:@"63BFF3"] backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        UIViewController * target = [[CTMediator sharedInstance]ct_showWebWithUrl:API_CHARONTV_AGREEMENT_USER titleStr:@"用户协议" showNav:YES closeHandle:^{}];
        [self.navigationController pushViewController:target animated:YES];
    }];
    
    NSString *string2 = @"《隐私政策》";
    NSRange range2 = [text rangeOfString:string2];
    [attrText addAttributes:@{NSUnderlineStyleAttributeName: @(1)} range:range2];
    [attrText setTextHighlightRange:range2 color:[UIColor colorFromHexRGB:@"63BFF3"] backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        UIViewController * target = [[CTMediator sharedInstance]ct_showWebWithUrl:API_CHARONTV_AGREEMENT_PRIVACY titleStr:@"隐私政策" showNav:YES closeHandle:^{}];
        [self.navigationController pushViewController:target animated:YES];
    }];
    
    label.attributedText = attrText;
    label.textAlignment = NSTextAlignmentLeft;
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selectButton.mas_right).offset(2);
        make.centerY.mas_equalTo(self.selectButton.mas_centerY);
    }];
}
- (IBAction)touchSelectButton:(id)sender {
    self.selectButton.selected = !self.selectButton.selected;
}


- (IBAction)touchJoneButton:(id)sender {
    if (self.selectButton.selected == YES){
        [appUserDefaults setObject:@"1" forKey:@"TVFirstBeginYinDao"];
        AppDelegate *del = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [del pushHome];
        


    }else{
        [WSToast simple:APPLocalized(@"請先閱讀並同意《用戶協議》，《隱私政策》和《第三方Ushare服務和隱私條款》")];
    }
}
- (IBAction)toucheJueButton:(id)sender {
    exit(1);
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
